--- title: '[RC17]Subset for Oligodendroglia' author: "Nina-Lydia Kazakou" date: "09/03/2022" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` # Set-up ### Load libraries ```{r message=FALSE, warning=FALSE} library(SingleCellExperiment) library(Seurat) library(tidyverse) library(Matrix) library(scales) library(cowplot) library(RCurl) library(scDblFinder) library(Matrix) library(ggplot2) library(edgeR) library(dplyr) library(ggsci) library(here) ``` ### Colour Palette ```{r load_palette} mypal <- pal_npg("nrc", alpha = 0.7)(10) mypal2 <-pal_tron("legacy", alpha = 0.7)(7) mypal3<-pal_lancet("lanonc", alpha = 0.7)(9) mypal4<-pal_simpsons(palette = c("springfield"), alpha = 0.7)(16) mypal5 <- pal_rickandmorty(palette = c("schwifty"), alpha = 0.7)(6) mypal6 <- pal_futurama(palette = c("planetexpress"), alpha = 0.7)(5) mypal7 <- pal_startrek(palette = c("uniform"), alpha = 0.7)(5) mycoloursP<- c(mypal, mypal2, mypal3, mypal4) ``` ### Load object ```{r} RC17_norm <- readRDS(here("data", "Processed", "AllCells", "RC17_AllCells_srt.rds")) ``` ```{r fig.height=4, fig.width=8} Idents(RC17_norm) <- "RNA_snn_res.0.8" FeaturePlot(RC17_norm, features = c("OLIG2", "SOX10"), label = TRUE) & NoLegend() ``` ```{r fig.height=6, fig.width=12} VlnPlot(RC17_norm, features = c("OLIG1", "OLIG2", "SOX10"), cols = mycoloursP, group.by = "RNA_snn_res.0.8", pt.size = 0.2, ncol = 2) ``` ## Subset for Oligodendroglia I will subset my dataset based on OLIG2 & SOX10 expression. I will subset for clusters 4, 12, 14, 18, 19, 20 as oligodendroglia. ```{r} oligos <- subset(RC17_norm, idents = c(4,12,14,18,19,20)) ``` #### Some extra plots ```{r fig.height=4, fig.width=14} Idents(oligos) <- "Sample" VlnPlot(oligos, features = c("nFeature_RNA", "nCount_RNA", "subsets_Mito_percent"), pt.size = 0.2, cols = mycoloursP) ``` ```{r fig.height=4, fig.width=8} plot3 <- FeatureScatter(oligos, feature1 = "nCount_RNA", feature2 = "subsets_Mito_percent", cols = mycoloursP) plot4 <- FeatureScatter(oligos, feature1 = "nCount_RNA", feature2 = "nFeature_RNA", cols = mycoloursP) plot3 + plot4 ``` ### Re-analyze subsetted srt ```{r FindVariableFeatures, message=FALSE, warning=FALSE} oligos <- FindVariableFeatures(oligos, selection.method = "vst", nfeatures = 2000) ``` ```{r top10_VariableFeatures} top10 <- head(VariableFeatures(oligos), 10) ``` ```{r} plot5 <- VariableFeaturePlot(oligos, cols = mycoloursP[4:5]) plot6 <- LabelPoints(plot = plot5, points = top10, repel = TRUE, xnudge = 0, ynudge = 0) plot6 ``` ```{r ScaleData, message=FALSE, warning=FALSE} all_genes <- rownames(oligos) oligos <- ScaleData(oligos, features= all_genes) ``` ```{r Linear_Dimensional_Reduction} oligos <- RunPCA(oligos, features = VariableFeatures(object = oligos)) ``` ```{r PCA_plot, fig.height=4, fig.width=6} DimPlot(oligos, reduction = "pca", cols = mycoloursP, pt.size = 1) ``` ```{r ElbowPlot, fig.height=4, fig.width=6} ElbowPlot(oligos) ``` Load original object: ```{r} new_oligos <- oligos rm(oligos) dim(new_oligos) ``` ```{r Load_Original_OL_object} oligos <- readRDS(here("data", "Processed", "Original_Objects", "RC17_oligos.rds")) dim(oligos) ``` ```{r} oligos@meta.data$RC17_AllCell_ClusterID <- new_oligos@meta.data$ClusterID oligos@meta.data$Original_Dataset <- new_oligos@meta.data$Dataset oligos@meta.data$RC17_AllCell_RNA_snn_res.0.8 <- new_oligos@meta.data$RNA_snn_res.0.8 oligos@meta.data$outlier <- oligos@meta.data$discard oligos@meta.data$Dataset <- oligos@meta.data$RC17_Monolayer_OL oligos@meta.data$percent.mito <- NULL oligos@meta.data$LibSize_low <- NULL oligos@meta.data$outlier <- oligos@meta.data$discard oligos@meta.data$Dataset <- oligos@meta.data$RC17_Monolayer_OL oligos@meta.data$LibSize_high <- NULL oligos@meta.data$low_nFeatures <- NULL oligos@meta.data$high_nFeatures <- NULL oligos@meta.data$discard <- NULL oligos@meta.data$ScaterQC <- NULL oligos@meta.data$scDblFinder.sample <- NULL oligos@meta.data$scDblFinder.cluster <- NULL oligos@meta.data$scDblFinder.ratio <- NULL oligos@meta.data$scDblFinder.weighted <- NULL oligos@meta.data$scDblFinder.nearestClass <- NULL oligos@meta.data$scDblFinder.difficulty <- NULL oligos@meta.data$scDblFinder.cxds_score <- NULL oligos@meta.data$scDblFinder.mostLikelyOrigin <- NULL oligos@meta.data$scDblFinder.originAmbiguous <- NULL oligos@meta.data$high_subsets_MitoPerc <- NULL oligos@meta.data$label <- NULL oligos@meta.data$RNA_snn_res.0.5 <- NULL oligos@meta.data$RNA_snn_res.0.6 <- NULL oligos@meta.data$RNA_snn_res.0.8 <- NULL oligos@meta.data$RNA_snn_res.0.1 <- NULL oligos@meta.data$RNA_snn_res.0.2 <- NULL oligos@meta.data$RNA_snn_res.0.3 <- NULL oligos@meta.data$RNA_snn_res.0.4 <- NULL oligos@meta.data$RNA_snn_res.0.7 <- NULL oligos@meta.data$RNA_snn_res.0.9 <- NULL oligos@meta.data$RNA_snn_res.1 <- NULL oligos@meta.data$seurat_clusters <- NULL oligos@meta.data$CelltypeOL <- NULL oligos@meta.data$Cluster_id <- NULL oligos@meta.data$Tissue <- NULL head(oligos@meta.data, 2) ``` ```{r Clustering, message=FALSE, warning=FALSE} oligos <- FindNeighbors(oligos, dims = 1:12, return.neighbor = TRUE, reduction = "pca") oligos <- FindClusters(oligos, resolution = c(0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1)) head((oligos), 2) ``` ```{r Non-Linear_Dimensional_Reduction, message=FALSE} oligos <- RunUMAP(oligos, dims = 1:12) ``` Here, I will plot the different resolution calculated. I start with a resolution that is really low, just enough to differentiate between oligodendrocytes and OPCs.Then, I increase the resolutions incrementaly and only keep resolutions that are associated with the appearance of a new cluster. I stop at a resolutions where I have completely overclustered the cells; I will continue until resolution 1 is reached. ```{r fig.height=4, fig.width=6} DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.01", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.05", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.1", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.2", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.3", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.4", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.5", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.6", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.7", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.8", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.0.9", label = T, label.size = 6) + NoLegend() DimPlot(oligos, reduction = "umap", cols= mycoloursP[6:40], group.by = "RNA_snn_res.1", label = T, label.size = 6) + NoLegend() ``` ```{r eval=FALSE} dir.create(here("Data", "Processed", "Oligodendroglia")) saveRDS(oligos, here("Data", "Processed", "Oligodendroglia", "oligos_initial_srt.rds")) ``` ```{r} sessionInfo() ```